package com.ccl.iot.dialogs;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.ccl.iot.R;

/**
 * 创建者     王浩
 * 创建时间   2017/5/5 9:41
 * 描述	      ${TODO}
 */

public abstract class TitleDialog extends CustomDialog {


    private TextView mTitle;
    private Button mBtnLeft;
    private Button mBtnRight;
    private FrameLayout mContainer;

    public TitleDialog(Context context) {
        super(context, R.style.DialogTheme);
        mContainer.addView(getContentView());
        mBtnLeft.setOnClickListener(mOnClickListener);
        mBtnRight.setOnClickListener(mOnClickListener);
    }

    private View.OnClickListener mOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()){
                case R.id.dialog_btn_left:
                    onLeftButtonClick(v);
                    break;
                case R.id.dialog_btn_right:
                    onRightButtonClick(v);
                    break;
            }
        }
    };

    @Override
    public View getView() {
        View view = View.inflate(getContext(), R.layout.dialog_title_layout, null);
        mTitle = (TextView) view.findViewById(R.id.dialog_title);
        mBtnLeft = (Button) view.findViewById(R.id.dialog_btn_left);
        mBtnRight = (Button) view.findViewById(R.id.dialog_btn_right);
        mContainer = (FrameLayout) view.findViewById(R.id.dialog_fl_container);
        return view;
    }

    public void setTitle(String title){
        mTitle.setText(title);
    }

    public void setTitle(int titleId){
        mTitle.setText(titleId);
    }

    public void setBottomButtonText(String leftButton, String rightButton){
        mBtnLeft.setText(leftButton);
        mBtnRight.setText(rightButton);
    }

    public void setBottomButtonText(int leftButtonId, int rightButtonId){
        mBtnLeft.setText(leftButtonId);
        mBtnRight.setText(rightButtonId);
    }

    public abstract View getContentView();

    public abstract void onLeftButtonClick(View v);

    public abstract void onRightButtonClick(View v);

}
